<?php
namespace app\controller\common;

use app\common\controller\_BaseController;
use think\captcha\Captcha;

class OtherController extends _BaseController
{	
	protected $rule = [
		'verifykey|验证码标识' => 'require|length:1,64|alphaNum',
	];

	protected $scene = [
		'captcha'			=> ['verifykey'],
	];

	protected function initialize()
	{	
		parent::initialize();
		$this->filterData();

		switch ($this->action) {
			case 'captcha':

				break;
			default:
				# code...
				break;
		}
		$this->check();
	}
	/**
	 * @api {POST} /common/other/captcha 获取验证码
	 * @apiVersion 0.0.1
	 * @apiGroup Common
	 *
	 * @apiParam {String} verifykey 验证码标识
	 *
	 * @apiParamExample {json} Request-Example:
	 * {
	 *     "verifykey": "f59bd65f7edafb087a81d4dca06c4910",
	 * }
	 * 
	 */
	public function captchaAction()
	{   
		$captcha = new Captcha(
			[	
				'fontSize'	=> 20,
			 	'length'    => 4,   
    			'useNoise'  => false, 
    			'fontttf'	=> '4.ttf',
    			'codeSet'	=> '0123456789',
    			'useCurve'	=> false,
			]);
        return $captcha->entry($this->data['verifykey']);
	}
}
